<template>
  <div class='container'>
    <el-dialog v-bind="$attrs" :visible="showUpdate" @close="close" width="400px">
      <el-form ref="formRef" :model="form" :rules="rules" size="small" label-width="100px">
        <el-form-item label="所属学科" prop="subjectID">
          <el-select v-model="form.subjectID" placeholder="请选择所属学科" clearable :style="{width: '100%'}">
            <el-option
            v-for="(item, index) in subjectIDOptions"
              :key="index"
              :label="item.subjectName"
              :value="item.subjectID"
              :disabled="item.disabled">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="目录名称" prop="directoryName">
      <el-input v-model="form.directoryName" placeholder="请输入目录名称" clearable :style="{width: '100%'}">

      </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { list as dieList, update} from '../../api/hmmm/directorys'
export default {
  // inheritAttrs: false,
  components: {},
  props: [
    'showUpdate', // 接收的是showUpdate的值
  ],
  data() {
    return {
      form: {
        subjectID: undefined,
        directoryName: undefined,
      },
      rules: {
        subjectID: [{
          required: true,
          message: '请选择所属学科',
          trigger: 'change'
        }],
        directoryName: [{
          required: true,
          message: '请输入目录名称',
          trigger: 'blur'
        }],
      },
      subjectIDOptions: []
    }
  },
  computed: {},
  created () {
    this.getTableData()
  },
  mounted () { },
  methods: {
    async getTableData () {
      const { data } = await dieList(this.Query)
      // console.log(data)
      this.subjectIDOptions = data.items
    },

    onOpen () {
    },
    close () {
      this.$refs['formRef'].resetFields()
      this.$emit('update:showUpdate',  false)
    },
    handelConfirm() {
      this.$refs['formRef'].validate(async (valid) => {
        if (!valid) return
        const res = await update(this.form)
        // 告诉父组件的list要更新
        this.$parent.getTableData()
        this.close()
      })
    },
  },
}
</script>

<style scoped lang='less'></style>
